package gpstools.data;

import generated.ped.PolarExerciseData;

import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

public class PolarMarshaller {

	public PolarExerciseData unmarshall(InputStream input) throws UnsupportedFormatException {
		try {
			JAXBContext context = JAXBContext.newInstance("generated.ped");
			Unmarshaller unmarshaller = context.createUnmarshaller();
			@SuppressWarnings("unchecked")
			JAXBElement<PolarExerciseData> root = (JAXBElement<PolarExerciseData>) unmarshaller.unmarshal(input);
			return root != null ? root.getValue() : null;
		} catch (JAXBException e) {
			throw new UnsupportedFormatException(e);
		}
	}

}
